<template>
  <div class="mes-setting" v-if="config">
    <div class="mes-setting-toolbar">
      <div>
        <span>{{
          $srv.getI18nByPath('piece.oMesSetting.signboardplacement')
        }}</span>
      </div>
      <div>
        <Button size="small" @click="addBoard">
          {{ $srv.getI18nByPath('piece.oMesSetting.addsignboard') }}
        </Button>
      </div>
    </div>
    <div
      class="mes-setting-part"
      v-for="(board, idx) of config"
      :key="board.id"
    >
      <div class="mes-setting-input">
        <div class="title">
          <Row type="flex" justify="space-between"
            ><i-col span="12">{{
              $srv.getI18nByPath('piece.oMesSetting.signboard') + (idx + 1)
            }}</i-col
            ><i-col><Icon type="md-close" @click="removeBoard(idx)"/></i-col
          ></Row>
        </div>
        <div>
          <Input
            :placeholder="$srv.getI18nByPath('piece.oMesSetting.secondstostay')"
            v-model="board.stayCount"
          />
          <Row style="height: 10px"></Row>
          <Row>
            <i-col span="24">
              {{ $srv.getI18nByPath('piece.oMesSetting.backgroundcolor') }}：
              <ColorPicker size="small" v-model="board.background" />
            </i-col>
          </Row>
        </div>
      </div>
      <o-chart-setting
        v-model="board.charts"
        @change="saveChanges"
        :isMes="true"
      ></o-chart-setting>
    </div>
  </div>
</template>

<script lang="ts">
import { parse } from 'qs';
import { Component, Prop, Watch, Model, Vue } from 'vue-property-decorator';
import { Tsrv } from '@/services';
import oChartSetting from './o-chart-setting.vue';

@Component({
  components: {
    oChartSetting
  }
})
export default class oMesSetting extends Vue {
  @Model('modelchange') config: any;

  mounted() {
    this.saveChanges();
  }

  private saveChanges() {
    this.$emit('modelchange', this.config);
    this.$emit('change');
  }

  private addBoard() {
    this.config.push({
      id: Tsrv.utils.uniqueId(),
      background: '',
      stayCount: '',
      charts: []
    });
    this.saveChanges();
  }

  private removeBoard(index) {
    this.config.splice(index, 1);
    this.saveChanges();
  }
}
</script>

<style lang="scss" scoped>
.mes-setting {
  padding: 10px 0;
  .mes-setting-toolbar {
    display: flex;
    justify-content: space-between;
    span {
      font-weight: bold;
    }
  }
  .mes-setting-input {
    padding: 10px 0;
    .title {
      font-weight: bold;
      margin-bottom: 10px;
    }
  }
}
</style>
